package com.longder.kindergarten.controller;

import com.longder.kindergarten.entity.dto.Response;
import com.longder.kindergarten.entity.po.Course;
import com.longder.kindergarten.service.CourseManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 每日所学管理
 */
@Slf4j
@RestController
@RequestMapping("/courseManage")
public class CourseManageController {

    @Resource
    private CourseManageService courseManageService;

    /**
     * 添加或修改课程
     */
    @PostMapping("/addOrUpdateCourse")
    public Response addOrUpdateCourse(@RequestBody Course course){
        try{
            courseManageService.addOrUpdateCourse(course);
            return Response.success("保存成功");
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return Response.error(e.getMessage());
        }
    }

    /**
     * 查询某个课程详情
     */
    @RequestMapping("/getCourse/{courseId}")
    public Response getCourse(@PathVariable("courseId")Long courseId){
        return Response.success(courseManageService.getCourse(courseId));
    }

    /**
     * 查询某个班级的
     * @return
     */
    @GetMapping("/listCourse/{classId}")
    public Response listCourse(@PathVariable("classId")Long classId){
        return Response.success(courseManageService.listByClassId(classId));
    }


}
